# Maintainer: Naveen M K <naveen521kk@gmail.com>

_realname=dust
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.8.5
pkgrel=2
pkgdesc="A more intuitive version of du in rust  (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/bootandy/dust'
license=(APACHE)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-rust"
)
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz::${url}/archive/refs/tags/v${pkgver}.tar.gz"
        "ntapi-link-ntdll-arm64.patch")
sha256sums=('0eff8b1b4e53f5ec2ffc0cfb9e5500bf27a9a5a68b1ff115c98facb4d20a7b7c'
            'c17674896bd2cd559fdf48812200096e5dcd93160874c05a46f21585d8202f16')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  cargo vendor \
    --locked \
    --versioned-dirs
  mkdir -p .cargo
  cat >> .cargo/config.toml <<END

[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"
END

  patch -d vendor/ntapi-0.4.0 -Np1 -i "${srcdir}/ntapi-link-ntdll-arm64.patch"
}

build() {
  cd "${srcdir}"
  cp -r ${_realname}-${pkgver} build-${MSYSTEM}
  cd build-${MSYSTEM}
  ${MINGW_PREFIX}/bin/cargo build \
    --release \
    --frozen
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/cargo install \
    --frozen \
    --offline \
    --no-track \
    --path . \
    --root ${pkgdir}${MINGW_PREFIX}

  # Package licenses
  install -Dm644 LICENSE \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/$pkgname/LICENSE
}
